package com.xisoft;

import com.xisoft.base.core.listener.MyApplicationContextInitializer;
import com.xisoft.base.core.listener.MyApplicationListener;
import com.xisoft.base.core.listener.MyBootstrapRegistryInitializer;
import com.xisoft.common.pubEnv.StringUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;

// @SpringBootApplication
@EnableTransactionManagement
@SpringBootApplication (exclude = {DataSourceAutoConfiguration.class})
@MapperScan (basePackages = {"com.xisoft.**"})
@ComponentScan (basePackages = {"com.xisoft.**"})
public class DesignServiceApplication
{

    public static void main(String[] args) throws UnknownHostException
    {
        // Clock defaultClock = Clock.systemDefaultZone();
        // Instant startTime = Instant.now(defaultClock);
        Instant startTime = Instant.now();
        System.err.println("🚀开始启动：" + startTime.atOffset(ZoneOffset.ofHours(8)));
        System.setProperty("starttime", startTime.getEpochSecond() + "");
        SpringApplication application = new SpringApplication(DesignServiceApplication.class);
        application.addInitializers(new MyApplicationContextInitializer());
        application.addBootstrapRegistryInitializer(new MyBootstrapRegistryInitializer());
        application.addListeners(new MyApplicationListener());
        // application.addPrimarySources();
        ConfigurableApplicationContext appContext = application.run(args);
        // SpringApplication.run(DesignServiceApplication.class, args);
        Environment env = appContext.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = StringUtil.valueOfEmpty(env.getProperty("server.servlet.context-path"));
        System.err.println("----------------------------------------------------------\n\t" +
                                   "Application Spring-Boot is running! Access URLs:\n\t" +
                                   "Network: \thttp://" + ip + ":" + port + path + "/index.html\n\t" +
                                   "Network: \thttp://127.0.0.1:" + port + path + "/index.html\n\t" +
                                   "Local: \t\thttp://localhost:" + port + path + "/index.html\n" +
                                   "----------------------------------------------------------");
        System.err.println(String.format("🌏启动完成时间是：{[%s]}一共运行：{[%s ms]}\r\n",
                                         Instant.now().atOffset(ZoneOffset.ofHours(8)),
                                         ChronoUnit.MILLIS.between(startTime, Instant.now())));

        System.err.println("✄—————————(◕‿◕✿)💞ꦿ完美分割线❀split line❤———————————————\n\n");

    }

}
